// https://leetcode.cn/problems/best-time-to-buy-and-sell-stock-with-cooldown/
// Created by ade on 2022/10/24.
// 卖出股票后，你无法在第二天买入股票 (即冷冻期为 1 天)。 计算最大利润
#include <queue>
#include <vector>
#include <iostream>

using namespace std;


class Solution {
public:
    /**
     * 思考：
     * 状态：
     *  1.持有股票中              0   dp[i][0] = max(dp[i-1][0], dp[i-1][2]-price[i]) 因为买的是第i天的股票，所以这里是price[i]
     *  2.不持有股票且处于冷冻期   1   dp[i][1] = dp[i-1][0]+price[i]
     *  3.不持有股票且不处于冷冻期 2   dp[i][2] = max(dp[i-1][1],dp[i-1][2])
     *
     *
     * @param prices
     * @return
     */
    int maxProfit(vector<int> &prices) {
        if (prices.empty()) return 0;
        int n = prices.size();
        vector <vector<int>> dp(n,vector<int>(3));
        dp[0][0] = -prices[0];
        for (int i = 1; i < n; i++) {
            dp[i][0] = max(dp[i - 1][0], dp[i - 1][2] - prices[i]);
            dp[i][1] = dp[i - 1][0] + prices[i];
            dp[i][2] = max(dp[i - 1][1], dp[i - 1][2]);
        }
        return max(dp[n - 1][1], dp[n - 1][2]);
    }
};


int main() {
    Solution so;
    vector<int> nums = {2, 1, -1, 3, 0, 2};
    cout << so.maxProfit(nums);

    return 0;
}